from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2023-01-10 14:02:38.452640
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Tue, 10, Jan, 2023
Time: 14:02:44
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -51.3713
Nobs: 897.000 HQIC: -51.6688
Log likelihood: 11890.9 FPE: 3.02428e-23
AIC: -51.8528 Det(Omega_mle): 2.73709e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.296986 0.048689 6.100 0.000
L1.Burgenland 0.107190 0.033725 3.178 0.001
L1.Kärnten -0.106222 0.018095 -5.870 0.000
L1.Niederösterreich 0.212212 0.070708 3.001 0.003
L1.Oberösterreich 0.077399 0.066783 1.159 0.246
L1.Salzburg 0.251356 0.035817 7.018 0.000
L1.Steiermark 0.032221 0.047015 0.685 0.493
L1.Tirol 0.125163 0.038099 3.285 0.001
L1.Vorarlberg -0.059799 0.032826 -1.822 0.069
L1.Wien 0.067413 0.059587 1.131 0.258
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.059877 0.099631 0.601 0.548
L1.Burgenland -0.007946 0.069010 -0.115 0.908
L1.Kärnten 0.048054 0.037028 1.298 0.194
L1.Niederösterreich -0.168634 0.144686 -1.166 0.244
L1.Oberösterreich 0.355277 0.136655 2.600 0.009
L1.Salzburg 0.286755 0.073290 3.913 0.000
L1.Steiermark 0.107675 0.096205 1.119 0.263
L1.Tirol 0.322188 0.077961 4.133 0.000
L1.Vorarlberg 0.024959 0.067170 0.372 0.710
L1.Wien -0.022508 0.121930 -0.185 0.854
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.202816 0.025514 7.949 0.000
L1.Burgenland 0.091983 0.017672 5.205 0.000
L1.Kärnten -0.008956 0.009482 -0.945 0.345
L1.Niederösterreich 0.265841 0.037052 7.175 0.000
L1.Oberösterreich 0.106969 0.034995 3.057 0.002
L1.Salzburg 0.054932 0.018768 2.927 0.003
L1.Steiermark 0.016943 0.024637 0.688 0.492
L1.Tirol 0.100379 0.019965 5.028 0.000
L1.Vorarlberg 0.057529 0.017201 3.344 0.001
L1.Wien 0.112389 0.031224 3.599 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.107438 0.026086 4.119 0.000
L1.Burgenland 0.049649 0.018068 2.748 0.006
L1.Kärnten -0.016268 0.009695 -1.678 0.093
L1.Niederösterreich 0.197473 0.037882 5.213 0.000
L1.Oberösterreich 0.271815 0.035780 7.597 0.000
L1.Salzburg 0.118664 0.019189 6.184 0.000
L1.Steiermark 0.101621 0.025189 4.034 0.000
L1.Tirol 0.124067 0.020412 6.078 0.000
L1.Vorarlberg 0.069986 0.017587 3.979 0.000
L1.Wien -0.025285 0.031924 -0.792 0.428
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.140582 0.046737 3.008 0.003
L1.Burgenland -0.053302 0.032372 -1.647 0.100
L1.Kärnten -0.035758 0.017370 -2.059 0.040
L1.Niederösterreich 0.162172 0.067872 2.389 0.017
L1.Oberösterreich 0.127764 0.064104 1.993 0.046
L1.Salzburg 0.292291 0.034380 8.502 0.000
L1.Steiermark 0.035254 0.045129 0.781 0.435
L1.Tirol 0.158227 0.036571 4.327 0.000
L1.Vorarlberg 0.108011 0.031509 3.428 0.001
L1.Wien 0.066438 0.057197 1.162 0.245
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.066879 0.037247 1.796 0.073
L1.Burgenland 0.039323 0.025799 1.524 0.127
L1.Kärnten 0.049457 0.013843 3.573 0.000
L1.Niederösterreich 0.224215 0.054091 4.145 0.000
L1.Oberösterreich 0.262045 0.051088 5.129 0.000
L1.Salzburg 0.061759 0.027400 2.254 0.024
L1.Steiermark -0.005635 0.035966 -0.157 0.876
L1.Tirol 0.158201 0.029146 5.428 0.000
L1.Vorarlberg 0.068033 0.025112 2.709 0.007
L1.Wien 0.076392 0.045583 1.676 0.094
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.199102 0.044951 4.429 0.000
L1.Burgenland 0.017626 0.031135 0.566 0.571
L1.Kärnten -0.057101 0.016706 -3.418 0.001
L1.Niederösterreich -0.101177 0.065278 -1.550 0.121
L1.Oberösterreich 0.175434 0.061655 2.845 0.004
L1.Salzburg 0.063492 0.033066 1.920 0.055
L1.Steiermark 0.224823 0.043405 5.180 0.000
L1.Tirol 0.477865 0.035174 13.586 0.000
L1.Vorarlberg 0.051119 0.030305 1.687 0.092
L1.Wien -0.049331 0.055011 -0.897 0.370
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.148562 0.050429 2.946 0.003
L1.Burgenland 0.000804 0.034929 0.023 0.982
L1.Kärnten 0.067438 0.018742 3.598 0.000
L1.Niederösterreich 0.203806 0.073233 2.783 0.005
L1.Oberösterreich -0.070855 0.069168 -1.024 0.306
L1.Salzburg 0.220402 0.037096 5.941 0.000
L1.Steiermark 0.108785 0.048694 2.234 0.025
L1.Tirol 0.081259 0.039460 2.059 0.039
L1.Vorarlberg 0.128875 0.033998 3.791 0.000
L1.Wien 0.111890 0.061715 1.813 0.070
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.358299 0.030022 11.935 0.000
L1.Burgenland 0.010273 0.020795 0.494 0.621
L1.Kärnten -0.025460 0.011158 -2.282 0.022
L1.Niederösterreich 0.228602 0.043598 5.243 0.000
L1.Oberösterreich 0.144323 0.041178 3.505 0.000
L1.Salzburg 0.054447 0.022085 2.465 0.014
L1.Steiermark -0.015216 0.028989 -0.525 0.600
L1.Tirol 0.121077 0.023492 5.154 0.000
L1.Vorarlberg 0.072872 0.020240 3.600 0.000
L1.Wien 0.052101 0.036741 1.418 0.156
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.039982 0.172798 0.188112 0.174373 0.153336 0.135575 0.071769 0.226777
Kärnten 0.039982 1.000000 0.005421 0.133654 0.027629 0.100410 0.426854 -0.047206 0.103422
Niederösterreich 0.172798 0.005421 1.000000 0.359350 0.179582 0.328214 0.147149 0.199831 0.352701
Oberösterreich 0.188112 0.133654 0.359350 1.000000 0.242280 0.352005 0.195451 0.185454 0.283331
Salzburg 0.174373 0.027629 0.179582 0.242280 1.000000 0.162196 0.148551 0.155320 0.147484
Steiermark 0.153336 0.100410 0.328214 0.352005 0.162196 1.000000 0.174151 0.154109 0.108662
Tirol 0.135575 0.426854 0.147149 0.195451 0.148551 0.174151 1.000000 0.130282 0.174319
Vorarlberg 0.071769 -0.047206 0.199831 0.185454 0.155320 0.154109 0.130282 1.000000 0.027576
Wien 0.226777 0.103422 0.352701 0.283331 0.147484 0.108662 0.174319 0.027576 1.000000